package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.DeptChange;
import com.itheima.pojo.Result;
import com.itheima.service.DeptChangeService;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class DeptChangeController {

    @Autowired
    private DeptChangeService deptChangeService;
    //private static Logger log= LoggerFactory.getILogger(DeptController.class);
    // @RequestMapping(value = "/depts",method = )
    @GetMapping("/deptchanges")
    public Result list(){
        log.info("查询全部部门数据");
        List<DeptChange> deptchangeList= deptChangeService.list();
        return Result.success(deptchangeList);
    }

    @PostMapping("/deptchanges")
    public Result add(@RequestBody DeptChange deptChange){
        Integer a=deptChange.getEmpId();
        Integer b=deptChange.getDeptId();
        log.info("新增部门:{}",deptChange);
        Integer ret= deptChangeService.func(a,b);//更改员工表 调任部门号
        String name1=deptChangeService.func4(b);//获取调任部门名
        deptChangeService.func6(a,name1);//更改员工表 调任部门名
        String name=deptChangeService.func5(ret);//获取原职位名
        String empname=deptChangeService.func7(a);//获取员工名
        deptChange.setEmpName(empname);
        deptChange.setDeptName(name);//原部门名
        deptChange.setDeptName1(name1);//
        deptChangeService.add(deptChange);
        deptChangeService.func3(a,ret);//显示原部门号

        return Result.success();
    }
//    @PutMapping("/deptchanges")
//    public Result update1(@RequestBody DeptChange deptChange){
//        log.info("修改部门为:{}",deptChange);
//        deptChangeService.update2(deptChange);
//        return Result.success();
//    }

}
